package cn.lili.modules.order.order.entity.dos;

import cn.lili.common.security.context.UserContext;
import cn.lili.common.utils.SnowFlake;
import cn.lili.modules.order.order.entity.enums.OrderStatusEnum;
import cn.lili.modules.order.order.entity.enums.PayStatusEnum;
import cn.lili.mybatis.model.BaseEntity;
import cn.lili.mybatis.model.BaseStandardEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.Objects;

@Data
@TableName("li_audit_order")
@ApiModel(value = "供应商审核订单表")
@EqualsAndHashCode(callSuper = true)
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AuditOrder extends BaseStandardEntity {

    @ApiModelProperty("订单编号")
    private String sn;

    @ApiModelProperty(value = "供应商ID")
    private String buyerId;

    @ApiModelProperty(value = "供应商昵称")
    private String nickname;

    @ApiModelProperty(value = "供应商所属城市站点ID")
    private String urbanId;

    /**
     * @see OrderStatusEnum
     */
    @ApiModelProperty(value = "订单状态")
    private String orderStatus;

    /**
     * @see PayStatusEnum
     */
    @ApiModelProperty(value = "付款状态")
    private String payStatus;

    @ApiModelProperty(value = "第三方支付发起交易号")
    private String outTradeNo;

    @ApiModelProperty(value = "第三方平台付款流水号")
    private String transactionId;


    @ApiModelProperty(value = "支付方式")
    private String paymentMethod;

    @ApiModelProperty(value = "支付时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date paymentTime;

    @ApiModelProperty(value = "总价格")
    private Double flowPrice;

    public AuditOrder(Double flowPrice, String urbanId) {
        this.setId(SnowFlake.getIdStr());
        this.setOrderStatus(OrderStatusEnum.UNPAID.name());
        this.setPayStatus(PayStatusEnum.UNPAID.name());
        this.setBuyerId(UserContext.getCurrentId());
        this.setNickname(Objects.requireNonNull(UserContext.getCurrentUser()).getNickName());
        this.setFlowPrice(flowPrice);
        this.setSn(SnowFlake.createStr("V"));
        this.setUrbanId(urbanId);
        this.setCreateTime(new Date());
    }
}
